#ifndef OPENOCD_LOADERS_FLASH_RM12XX_RM12XX_FLASH_H
#define OPENOCD_LOADERS_FLASH_RM12XX_RM12XX_FLASH_H
#include "rm12xx_flash_config.h"
#include <stdbool.h>
#include "FlashOS.h"
#include "_reg_spiflash.h"
#include "_reg_pmu_ctrl.h"
#include "_reg_clkrst.h"
#include "base_address.h"
#include "drv_flash_api.h"
#include "hal_spi_flash.h"

/* Flash loader parameters */
struct __attribute__((__packed__)) rm12xx_flash_params {
	uint32_t addr; /* Address in flash */
	uint32_t len;  /* Number of bytes */
	uint32_t cmd;  /* Command */
	uint32_t sync; /* Handshake signal */
};

/* Flash trigger signal */
enum rm12xx_flash_handshake {
	RM12XX_FLASH_LOADER_WAIT    = 0x0,       /* Idle */
	RM12XX_FLASH_LOADER_EXECUTE = 0xFFFFFFFF /* Execute Command */
};

/* Flash loader command */
enum rm12xx_flash_commands {
	RM12XX_FLASH_CMD_NO_ACTION = 0, /* No action, default value */
	RM12XX_FLASH_CMD_GET_FLASH_ID,  /* Get the internal flash ID */
	RM12XX_FLASH_CMD_ERASE_SECTORS, /* Erase unprotected sectors */
	RM12XX_FLASH_CMD_ERASE_ALL,     /* Erase all */
	RM12XX_FLASH_CMD_PROGRAM,       /* Program data */
};

/* Status */
enum rm12xx_flash_status {
	RM12XX_FLASH_STATUS_OK = 0,
	RM12XX_FLASH_STATUS_FAILED_UNKNOWN_COMMAND,
	RM12XX_FLASH_STATUS_FAILED,
	RM12XX_FLASH_STATUS_FAILED_TIMEOUT,
};

#endif /* OPENOCD_LOADERS_FLASH_RM12XX_RM12XX_FLASH_H */

